import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  routes: constantRoutes
}
const mutations = {
  // 设置菜单路由页面
  SET_ROUTES_MENUS(store, routes) {
    store.routes = [...constantRoutes, ...routes]
  },
  // 清空路由
  CLEAR_ROUTES_MENUS(store) {
    store.routes = constantRoutes
  }
}
const actions = {
  // 筛选权限路由
  filtersRoute(store) {
    const { menus } = store.rootGetters.roles
    console.log(menus)
    const routes = asyncRoutes.filter(item => menus.includes(item.name))
    store.commit('SET_ROUTES_MENUS', routes)
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
